package leetcode.剑指offer.前40;

import org.junit.Test;

import java.util.PriorityQueue;
import java.util.Stack;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/29 11:30
 * @description :https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/
 */
public class 剑指_30_包含min函数的栈 {
    @Test
    public void test() {
        MinStack minStack = new MinStack();
        minStack.push(-1);
        System.out.println(minStack.top());
        System.out.println(minStack.min());
    }

    class MinStack {

        PriorityQueue<Integer> queue;
        Stack<Integer> stack;

        /** initialize your data structure here. */
        public MinStack() {
            queue = new PriorityQueue<>();
            stack = new Stack<>();
        }

        public void push(int x) {
            stack.push(x);
            queue.offer(x);
        }

        public void pop() {
            queue.remove(stack.pop());
        }

        public int top() {
            return stack.peek();
        }

        public int min() {
            return queue.peek();
        }
    }

}
